{
 "cells": [
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.by import By\n",
    "\n",
    "driver = webdriver.Edge()\n",
    "\n",
    "driver.get(\"https://www.bilibili.com/\")"
   ],
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-05-10T04:24:43.463399Z",
     "start_time": "2025-05-10T04:24:35.917464Z"
    }
   },
   "id": "initial_id",
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "# 1. Xpath定位搜索框\n",
    "input = driver.find_element(by=By.XPATH,value='//*[@id=\"nav-searchform\"]/div[1]/input')\n",
    "# 往input搜索框输入内容\n",
    "input.send_keys(\"美女跳舞\")\n",
    "# 定位搜索图标并确定\n",
    "driver.find_element(By.XPATH,'//*[@id=\"nav-searchform\"]/div[2]').click()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-05-10T04:24:50.655213Z",
     "start_time": "2025-05-10T04:24:50.481362Z"
    }
   },
   "id": "e4c15df78aca0677"
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "# 2. className定位视频\n",
    "driver.find_element(By.CLASS_NAME,\"v-img.bili-video-card__cover\").click()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-05-10T04:25:07.008593Z",
     "start_time": "2025-05-10T04:25:06.905381Z"
    }
   },
   "id": "fb2d5b9a4359a570"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
